//
//  UIBarButtonItem+Extension.swift
//  WeiBo
//
//  Created by 韩俊 on 15/12/5.
//  Copyright © 2015年 HanJun. All rights reserved.
//

import UIKit

let ItemTitleFontSize: CGFloat = 14

let ItemTitleColor: UIColor = UIColor(white: 80 / 255, alpha: 1)

extension UIBarButtonItem{
    
    convenience init(imgName: String? = nil, title: String? = nil, target: AnyObject?, action:Selector) {
        
        self.init()
        
        let button = UIButton()
        
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        if let img = imgName {
            
            button.setImage(UIImage(named: img), forState: .Normal)
            button.setImage(UIImage(named: "\(img)_highlighted"), forState: .Highlighted)
        }
        
        if let t = title {
            
            button.setTitle(t, forState: .Normal)
            button.setTitleColor(ItemTitleColor, forState: .Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
            button.titleLabel?.font = UIFont.systemFontOfSize(ItemTitleFontSize)
        }
        
        button.sizeToFit()
        
        customView = button
    }
    
 
}